<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!-- <title>新增收货地址</title> -->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="format-detection" content="telephone=no"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0,  maximum-scale=1.0"/>
    <meta name="format-detection" content="telephone=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
    <link rel="stylesheet" type="text/css" href="${ctxStatic}/shopcartstatic/css/public.css"/>
    <link rel="stylesheet" type="text/css" href="${ctxStatic}/shopcartstatic/css/reset.css"/>
</head>
<body style="height:auto;background: #e5e5e5;">
<div id="form1" style="display:none;"></div>
<div class="top1">
    <div class="top2">
        <a href="Javascript:history.go(-1)"><span class="top3">返回</span></a>

    </div>
    <c:if test="${home.id!=null}">
        <div class="top4">修改地址</div>
    </c:if>
    <c:if test="${!(home.id != null)}">
        <div class="top4" >新增地址</div>
    </c:if>
</div>
<div class="div_w"></div>
    <div style="height:40px;width:100%;background: #ffffff;border-top: 1.5px solid #e5e5e5;"class="clearfix">

        <span style="float:left; margin-left: 3%;margin-top:3%">收货人：</span>
        <input id="receiver" name="user.name" style="width:60% ;height: 100%;border:none" placeholder="收货人姓名"
               value="${home.user.name}"/>
    </div>
    <div style="height:40px;width:100%;background: #ffffff;border-top: 1.5px solid #e5e5e5;" class="clearfix">
        <span style="float:left; margin-left: 3%;margin-top:3%">手机号：</span>
        <input id="phone" name="tel" style="width:60% ;height: 100%;border:none" placeholder="收货人手机号"
               value="${home.tel}"/>
    </div>
    <div style="height:40px;width:100%;background: #ffffff;border-top: 1.5px solid #e5e5e5;" class="clearfix">
        <span style="float:left; margin-left: 3%;margin-top:3%">地址：</span>
        <input id="address" name="address" style="width:60% ;height: 100%;border:none" placeholder="收货人地址"
               value="${home.address}"/>
    </div>
    <div style="height:80px;width:100%;background: #ffffff;border-top: 1.5px solid #e5e5e5;" class="clearfix">
        <input id="addressInfo" name="remarks" style="width:95% ;height: 100%;margin-left: 3%;border:none "
               placeholder="详细地址" value="${home.remarks}"/>
        <input type="hidden" id="homeid" value="${home.id}">
    </div>



    <div style="height:40px;width:100%;" class="clearfix">
        <input type="radio" value="1" name="isDefault" id="isDefault" style="float:left; margin-left: 3%;margin-top:3%">
        <button id="homeclicke"><span style="float:left;margin-top:2%">设为默认地址</span></button>
    </div>




    <c:if test="${home.id!=null}">
        <div style="height:40px;width:100%;background: #ffffff;border-top: 1.5px solid #e5e5e5;"class="clearfix" id="addhome">
            <input style="height: 25px;width: 150px;font-size:22px;float:left;margin-left: 25%;margin-top: 1.5%;color: red"   type="button" value="保存收货地址"><br>
        </div>

        <div style="height:40px;width:100%;background: #ffffff;border-top: 1.5px solid #e5e5e5;"class="clearfix">
            <a href="/shop/client/deletehome?homeid=${home.id}">
                <span style="color: red;font-size:25px;float:left;margin-left: 25%;margin-top: 3%">删除收货地址</span>
            </a>
        </div>
    </c:if>

    <c:if test="${!(home.id != null)}">
        <div style="height:40px;width:100%;background: #ffffff;border-top: 1.5px solid #e5e5e5;"class="clearfix" id="addhome">
            <input style="height: 25px;width: 150px;font-size:22px;float:left;margin-left: 25%;margin-top: 1.5%;color: red" type="button" value="确认收货地址">
        </div>
    </c:if>
<script src="${ctxStatic}/shopcartstatic/js/jquery-1.6.2.min.js "></script>
<script type="text/javascript">

</script>
</body>
<script type="text/javascript">
    $("#homeclicke").click(function () {
        $("#isDefault").val("0");
    });

    $("#addhome").click(function () {
        var homeid = $("#homeid").val();
        var tel = $("#phone").val();
        var address = $("#address").val();
        var remarks = $("#addressInfo").val();
        var defalut = $("#isDefault").val();
        var home = {
            id: homeid,
            address: address,
            tel: tel,
            remarks: remarks,
            defalut: defalut
        }
        $.ajax({
            url:"/shop/client/addhome",
            dataType: 'json',
            data: home,
            cache: false,
            success: function (data) {
                if (data.status ==0) {
                    alert(data.message);
                    window.location.href = "customer";
                }else {
                    alert(data.message);
                    window.location.href = "login";
                }
            }
        })
    });


</script>
</html>
